package com.iflytek.day21;

import java.util.ArrayList;
/*
    思路：
        1:定义学生类
        2:创建集合对象
        3:创建学生对象
        4:添加学生对象到集合中
        5:遍历集合，采用通用遍历格式实现
 */

public class _06_ArrayListDemo {
  public static void main(String[] args) {
    // 创建集合对象
    ArrayList<Student> array = new ArrayList<>();

    // 创建学生对象
    Student s1 = new Student("林青霞", 30);
    Student s2 = new Student("风清扬", 33);
    Student s3 = new Student("张曼玉", 18);

    // 添加学生对象到集合中
    array.add(s1);
    array.add(s2);
    array.add(s3);

    // 遍历集合，采用通用遍历格式实现
    for (int i = 0; i < array.size(); i++) {
      Student s = array.get(i);
      System.out.println(s.getName() + "," + s.getAge());
    }
  }
}

class Student {
  private String name;
  private int age;

  public Student() {
  }

  public Student(String name, int age) {
    this.name = name;
    this.age = age;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    this.age = age;
  }
}
